/*
 * @lc app=leetcode.cn id=98 lang=cpp
 *
 * [98] 验证二叉搜索树
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution
{
public:
    bool isValidBST(TreeNode *root)
    {
        recursion(root);
        return flag;
    }

    bool flag = true;

    void recursion(TreeNode *root)
    {
        //终止条件
        if (!root)
            return ;
        
        if (root->left)
        {
            if (root->val <= root->left->val)
            {
                flag = false;
            }
        }

        if (root->right)
        {
            if (root->val >= root->right->val)
            {
                flag = false;
            }
        }

        recursion(root->left);
        recursion(root->right);
    }
};
// @lc code=end
